# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ilmbase

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
pkgrel=6
pkgdesc="Base libraries from ILM for OpenEXR (mingw-w64)"
arch=('any')
url="http://http://www.openexr.com/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "libtool")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("http://download.savannah.nongnu.org/releases/openexr/${_realname}-${pkgver}.tar.gz"
        ilmthread-mingw-win32.patch
        ilmthread-mingw-pthreads.patch
        ilmbase-2.1.0_obsolete-macros.patch
        cmake-soversion.patch
        cmake-install-binaries.patch
        pull93.patch)
md5sums=('8ba2f608191ad020e50277d8a3ba0850'
         '3a34cf48b52c2af0584ef3e8cf50499a'
         '8b9d9c6e4ed88dc9dfb80ce4f637460a'
         '1c9a320c8ab09c98abe9ecb80eb24e2e'
         'e2cda218f1651a1cd754e60cf131018a'
         'baaa4fa9467969a611c70e62efa1fe6b'
         'a077f53db4370a1f5a3f5ce4b6d86311')
prepare(){
  cd "$srcdir/${_realname}-$pkgver"
  # Use either one or the other of the ilmthread patches
  # depending on the sort of threads that you want.
  # patch -Np1 -i "$srcdir/ilmthread-mingw-win32.patch"
  patch -Np1 -i "$srcdir/ilmthread-mingw-pthreads.patch"
  patch -Np1 -i "$srcdir/ilmbase-2.1.0_obsolete-macros.patch"
  patch -Np1 -i "$srcdir/cmake-soversion.patch"
  patch -Np1 -i "$srcdir/cmake-install-binaries.patch"
  patch -Np2 -i "$srcdir/pull93.patch"
  #./bootstrap
}

build() {
  mkdir build-${CARCH}
  cd build-${CARCH}
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${pkgdir}${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}
  
  #-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--export-all-symbols"

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make install

  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/IlmBase.pc
}
